package com.alan.wifishare.view.ui;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.TextView;

import com.alan.wifishare.R;

/**
 * 
 * @ClassName:  TwoBtnDialog   
 * @Description:   带有两个按钮的对话框
 * @author: Alan.wang  
 * @date:   2015-02-10 14:12   
 * version:1.0.0
 */
public class TwoBtnDialog extends Dialog {

	private TextView tvTileContent;
	private TextView tvMessage;
	private TextView tvLeftBtn;
	private TextView tvRightBtn;
	private OnClickListener mLeftBtnListener;
	private OnClickListener mRightBtnListener;

	protected TwoBtnDialog(Context context) {
		super(context);
		initView(context);
	}

	public TwoBtnDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		initView(context);
	}

	public TwoBtnDialog(Context context, int theme) {
		super(context, theme);
		initView(context);
	}

	private void initView(Context context) {
		// super(context, R.style.custom_dialog1);
		this.setContentView(R.layout.two_btn_dialog);
		this.setCanceledOnTouchOutside(false);
		tvTileContent = (TextView) this.findViewById(R.id.tvTitleDialog);
		tvMessage = (TextView) this.findViewById(R.id.tvMessageDialog);
		tvLeftBtn = (TextView) this.findViewById(R.id.leftBtnDialog);
		tvRightBtn = (TextView) this.findViewById(R.id.rightBtnDialog);

		View.OnClickListener listener = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.leftBtnDialog:
					if (mLeftBtnListener != null) {
						mLeftBtnListener.onClick(TwoBtnDialog.this,
								Dialog.BUTTON_POSITIVE);
					}
					dismiss();
					break;
				case R.id.rightBtnDialog:
					if (mRightBtnListener != null) {
						mRightBtnListener.onClick(TwoBtnDialog.this,
								Dialog.BUTTON_NEGATIVE);
					}
					dismiss();
					break;
				default:
					break;
				}
			}
		};
		
		tvLeftBtn.setOnClickListener(listener);
		tvRightBtn.setOnClickListener(listener);
	}

	/**
	 * 设置标题信息
	 * @param title
	 */
	public void setTitle(String title) {
		tvTileContent.setText(title);
	}

	/**
	 * 设置中间的提示信息
	 * @param msg
	 */
	public void setMessage(CharSequence msg) {
		//tvMessage.setText(Html.fromHtml(msg));
		tvMessage.setText(msg);
	}
	
	/**
	 * 设置左按钮文字
	 * @param leftText
	 */
	public void setLeftBtnText(CharSequence leftText) {
		tvLeftBtn.setText(leftText);
	}
	
	/**
	 * 设置左右按钮文字
	 * @param rightText
	 */
	public void setRightBtnText(CharSequence rightText) {
		tvRightBtn.setText(rightText);
	}

	/**
	 * 设置左边按钮的文字的显示及点击监听器
	 * @param leftText 左边按钮显示的文字
	 * @param leftOnClickListener 左边按钮监听器
	 */
	public void setLeftBtn(CharSequence leftText,
			OnClickListener leftOnClickListener) {
		tvLeftBtn.setText(leftText);
		this.mLeftBtnListener = leftOnClickListener;
	}

	/**
	 * 设置右边按钮的文字显示及监听器
	 * @param rightText 右边按钮显示文字
	 * @param rightOnClickListener 右边按钮监听器
	 */
	public void setRightBtn(CharSequence rightText,
			OnClickListener rightOnClickListener) {
		tvRightBtn.setText(rightText);
		this.mRightBtnListener = rightOnClickListener;
	}
}
